package com.crm.system.controller.csd.reviewManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.csd.reviewManager.PutOnRecordInformationAddQO;
import com.crm.model.qo.csd.reviewManager.PutOnRecordInformationQO;
import com.crm.model.vo.csd.reviewManager.PutOnRecordInformationVO;
import com.crm.system.service.csd.reviewManager.PutOnRecordInformationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yincuimei
 * @Date 2021/8/10 14:03
 * (客服部)-审核管理-》备案信息
 */
@RequestMapping("/csd/putOnRecordInformation")
@RestController
public class PutOnRecordInformationController {
    @Autowired
    private PutOnRecordInformationService putOnRecordInformationService;

    /**
     * 备案信息列表
     * @author yincuimei
     */
    @PostMapping("/selectPutOnRecordInformationList")
    public DataResponse selectPutOnRecordInformationList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                         @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                                         @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                         PutOnRecordInformationQO putOnRecordInformationQO//查询条件
    ){
        try{
            DhPageInfo<PutOnRecordInformationVO> putOnRecordInformationVODhPageInfo = putOnRecordInformationService.selectPutOnRecordInformationVOList(putOnRecordInformationQO,pageIndex,pageSize,sortName,sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),putOnRecordInformationVODhPageInfo);
        }catch(Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 新增备案信息
     * @param putOnRecordInformationAddQO
     * @return
     */
    @PostMapping("/addPutOnRecordInformation")
    public DataResponse addPutOnRecordInformation(@RequestBody PutOnRecordInformationAddQO putOnRecordInformationAddQO){
        JSONObject resultJson = putOnRecordInformationService.insertPutOnRecordInformation(putOnRecordInformationAddQO);
        String code = resultJson.getString("code");
        if (!StringUtils.isBlank(code)) {
            return new DhResponse(code,resultJson.getString("message"));
        }
        return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
    }
}
